package com.freemarker;

import java.io.File;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.management.Attribute;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;

public class TestPo{

	public static void main(String[] args) throws Exception{
		
		Map<String, Object> root = new HashMap<String, Object>();

        root.put("packageName", "com.freemarker.java");
        root.put("className", "Person");
        root.put("author", "mutouos.com");

        List<Attribute> attr_list = new ArrayList<Attribute>();
        attr_list.add(new Attribute("id", "Long"));
        attr_list.add(new Attribute("name", "String"));
        attr_list.add(new Attribute("age", "Integer"));
        attr_list.add(new Attribute("hobby", "List<String>"));
        
        root.put("attrs", attr_list);
		
		
		Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
		File file = new File("d:/freemarker/templates");
		if(!file.exists()) {
			file.mkdir();
		}
        cfg.setDirectoryForTemplateLoading(file);    
        cfg.setDefaultEncoding("UTF-8");
        cfg.setClassicCompatible(true);
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        
        Template temp = cfg.getTemplate("person.ftl");
        
        Writer out = new OutputStreamWriter(System.out);
        temp.process(root, out);
	}
	
}
